package response

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data,omitempty"`
	Err  error  `json:"err,omitempty"`
}

// Success 成功响应
func Success(data any) Response {
	return Response{
		Code: 0,
		Msg:  "success",
		Data: data,
	}
}

// Error 错误响应
func Error(code int, msg string, err error) Response {
	return Response{
		Code: code,
		Msg:  msg,
		Err:  err,
	}
}

// 未登录错误
func Unauthorized(msg string, err error) Response {
	return Response{
		Code: 401,
		Msg:  msg,
		Err:  err,
	}
}

// 参数错误
func BadRequest(msg string, err error) Response {
	return Response{
		Code: 400,
		Msg:  msg,
		Err:  err,
	}
}
